Checking for existing of a module in a specified folder

Hello!

I'm trying to build an script, which automatically creates a new link module with a given name (in sourcecode "linkpurpose"), if the linkmodule doesn't exist, in the folder of a specified formal module (target).
Therefore I need to check, if this link module allready exists in the spezified folder.

To do this, I've written the follwing code, but it doesn't work the way I supposed it to do.
 

Module linkMod 
string linkModNameWithPath = path(targetMod) "//" linkPurpose 
if(!null current Module ) 
{ 
  previousCurrentModule = current Module 
  openedPrevious = true 
} 
string moduledescription = "Automatisch generiert durch: Zielspezifikation erstellen" 
 
if(exists (module linkModNameWithPath) == true) 
{ 
  infoBox "Das Linkmodul " linkPurpose  " existiert bereits." 
  linkMod = edit ( linkPurpose  ) 
  linkMod = current 
}//if - Linkmodul existiert bereits: Linkmodul oeffnen 
else 
{ 
 linkMod = create(linkModNameWithPath , moduledescription , manyToMany, true) 
 current = linkMod 
}//else - neues Linkmodul erstellen

 


My problem is, the funktion-call

 

if(exists (module linkModNameWithPath) == true)

returns true, even there is allready a link module with the specified name in the specified folder. So the create-command returns an error (wich is correct, of course).

I hope, I've managed to describe my problem in a way, that you could help me to deal with this!
Regards,
Alexander Karpa


SystemAdmin - Tue May 04 11:23:57 EDT 2010

Re: Checking for existing of a module in a specified folder
llandale - Tue May 04 17:58:23 EDT 2010

Its your double slashes. Use either double back-slashes "\\" or single front slashes "/", not double front slashes "//". Add <print linkModNameWithPath "\n"> at line 3 and you'll see the error in the link module name.

On other news...

Your exists function is returning false.

Your <linkMod = current> statement is redundant, and possibly an error, since I don't think the link module is current if its already open Edit.

Your attempt to maintain the current module is admirable, but worthless. Routinely do it this way:
Module mCurr = current()
Do stuff, open modules, etc
if (!null mCurr) current = mCurr

  • Louie

Strangely, even after all these years, I still have to think about which slash needs to be double. I type this: "\n" which I can do in my sleep, and then determine its this slash that's double \, then delete what I just typed in.

Re: Checking for existing of a module in a specified folder
SystemAdmin - Wed May 05 04:31:37 EDT 2010

Hi Louie,

thanks for your answer!
I tried the "/"-Seperator, and now my script works quite fine.

The thing you mentioned about dealing with the current module was quite helpfull too!